<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="reflectionproperty.gettype.html">« ReflectionProperty::getType</a></li>
      <li style="float: right;"><a href="reflectionproperty.hasdefaultvalue.html">ReflectionProperty::hasDefaultValue »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.reflectionproperty.html">ReflectionProperty</a></li>
    <li>Gets value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="reflectionproperty.getvalue" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionProperty::getValue</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionProperty::getValue</span> &mdash; <span class="dc-title">Gets value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionproperty.getvalue-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionProperty::getValue</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">object</span><span class="type"></span></span> <code class="parameter">$object</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   Gets the property&#039;s value.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionproperty.getvalue-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       If the property is non-static an object must be provided to fetch the
       property from. If you want to fetch the default property without
       providing an object use <span class="methodname"><a href="reflectionclass.getdefaultproperties.html" class="methodname">ReflectionClass::getDefaultProperties()</a></span>
       instead.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionproperty.getvalue-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The current value of the property.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-reflectionproperty.getvalue-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       Private and protected properties can be accessed by
       <span class="methodname"><strong>ReflectionProperty::getValue()</strong></span> right away.
       Previously, they needed to be made accessible by calling
       <span class="methodname"><a href="reflectionproperty.setaccessible.html" class="methodname">ReflectionProperty::setAccessible()</a></span>; otherwise
       a <span class="classname"><a href="class.reflectionexception.html" class="classname">ReflectionException</a></span> was thrown.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">object</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-reflectionproperty.getvalue-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5248">
    <p><strong>示例 #1 <span class="methodname"><strong>ReflectionProperty::getValue()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Foo&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;</span><span style="color: #0000BB">$staticProperty&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foobar'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;</span><span style="color: #0000BB">$property&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'barfoo'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;</span><span style="color: #0000BB">$privateProperty&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'foofoo'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$reflectionClass&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'staticProperty'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'property'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">Foo</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$reflectionProperty&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$reflectionClass</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getProperty</span><span style="color: #007700">(</span><span style="color: #DD0000">'privateProperty'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAccessible</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;only&nbsp;required&nbsp;prior&nbsp;to&nbsp;PHP&nbsp;8.1.0<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflectionProperty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">Foo</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(6) &quot;foobar&quot;
string(6) &quot;barfoo&quot;
string(6) &quot;foofoo&quot;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionproperty.getvalue-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="reflectionproperty.setvalue.html" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setValue()</a> - Set property value</span></li>
    <li class="member"><span class="methodname"><a href="reflectionproperty.setaccessible.html" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::setAccessible()</a> - Set property accessibility</span></li>
    <li class="member"><span class="methodname"><a href="reflectionclass.getdefaultproperties.html" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getDefaultProperties()</a> - 获取默认属性</span></li>
    <li class="member"><span class="methodname"><a href="reflectionclass.getstaticpropertyvalue.html" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getStaticPropertyValue()</a> - 获取静态（static）属性的值</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>